#import "BWSelectionLayer.h"
#import "BWGridGeometry.h"

@implementation BWSelectionLayer

+ (void) initialize
{
    [super initialize];
    
    [BWSelectionLayer setVersion: 1];

} // initialize


- (id) init
{
    if (self = [super init]) {
        isEmptySelection = YES;
    }

    return (self);

} // init

- (void) clearSelection
{
    isEmptySelection = YES;
} // clearSelection


- (void) selectStartRow: (int) sr
                 column: (int) sc
                 endRow: (int) er
                 column: (int) ec
{
    isEmptySelection = NO;

    startRow = sr;
    startColumn = sc;

    endColumn = ec;
    endRow = er;

    [self postChangeNotification];

} // selectStartRow


- (void) drawRect: (NSRect) rect
{
    if (!isEmptySelection) {
        NSRect anchorRect = [geometry rectForRow: startRow
                                      column: startColumn];
        NSRect oppositeRect = [geometry rectForRow: endRow
                                        column: endColumn];
        
        NSRect onion = NSUnionRect (anchorRect, oppositeRect);
        
        NSColor *color;
        color = [NSColor colorWithDeviceRed: 0.5
                         green: 0.5
                         blue: 0.7
                         alpha: 0.25];
        [color set];
        [NSBezierPath fillRect: onion];
    }

} // drawRect


- (BOOL) isEmptySelection
{
    return (isEmptySelection);
} // isEmptySelection


- (BWLayerKind) layerKind
{
    return (kLayerKind_Selection);
} // layerKind



- (void) encodeWithCoder: (NSCoder *) coder
{
    [super encodeWithCoder: coder];
    
} // encodeWithCoder


- (id) initWithCoder: (NSCoder *) coder
{
    if (self = [super initWithCoder: coder]) {
        isEmptySelection = YES;
    }

    return (self);

} // coder


@end // BWSelectionLayer

